import 'dart:developer';

import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:oktoast/oktoast.dart';
import 'package:school_safe_teacher/constans/route_constants.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    HomeWorkState state, Dispatch dispatch, ViewService viewService) {
  return body(
      child: Container(
        color: AppColors.MainBackColor,
        child: Column(
          children: [
            Container(
              child: myRightBar(
                  context: viewService.context,
                  title: "作业下发",
                  rightTitle: "作业记录",ontap: (){Navigator.of(viewService.context)
                  .pushNamed(RouteConstants.HOMEWORKlIST);

              }),
              color: Colors.white,
            ),
            Expanded(
                child: ListView(
              padding: EdgeInsets.zero,
              children: [
                Container(
                  margin: EdgeInsets.only(top: 10, left: 10, right: 10),
                  padding: EdgeInsets.fromLTRB(10, 0, 6, 5),
                  color: Colors.white,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      TextField(
                        onChanged: (String value){
                          state.textValue = value;
                        },
                        maxLines: 15,
                        inputFormatters: <TextInputFormatter>[
                          LengthLimitingTextInputFormatter(300) //限制长度
                        ],
                        decoration: InputDecoration(
                            hintText: '请输入作业内容',
                            border: InputBorder.none,
                            counterText: "最大长度不超过300"),
                      ),
//                      Container(
//                        padding: EdgeInsets.only(top: 10,left: (MediaQuery.of(viewService.context).size.width-261)/4,right: (MediaQuery.of(viewService.context).size.width-261)/4,bottom: 10),
//                        height: 95,
//                        child: ListView.separated(
//
//                          padding: EdgeInsets.zero,
//                          scrollDirection: Axis.horizontal,
//                          physics: NeverScrollableScrollPhysics(),
//                          shrinkWrap: true,
//                          itemCount: 3,
//                          itemBuilder: (BuildContext context, int index) {
//                            return GestureDetector(
//                              child: Image.asset(
//                                "images/homeWork_add@2x.png",
//                                width: 75,
//                                height: 75,
//                                fit: BoxFit.fill,
//                              ),
//                              onTap: () {
//                                double aa = (MediaQuery.of(viewService.context).size.width-245)/4;
//                                print(aa);
//
//                              },
//                            );
//                          },
//                          separatorBuilder: (BuildContext context, int index) {
//
//                            return Container(
//
//                              width: (MediaQuery.of(viewService.context).size.width-261)/4,
//                            );
//                          },
//                        ),
//                      ),
//                      Container(
//                        height: 30,
//                        child: Text("最多三张"),
//                      )
                    ],
                  ),
                ),
                GestureDetector(
                  child: Container(
                    height: 45,
                    margin: EdgeInsets.fromLTRB(25, 33, 25, 0),
                    alignment: Alignment.center,
                    width: MediaQuery.of(viewService.context).size.width - 50,
                    child: Text(
                      "提交",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 15,
                          fontWeight: FontWeight.normal),
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(25),
                      color: AppColors.editBackgroundColor,
                      gradient: LinearGradient(
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                        colors: [
                          AppColors.loginLeft,
                          AppColors.loginRight,
                        ],
                      ),
                    ),
                  ),
                  onTap: () {
                    dispatch(HomeWorkActionCreator.onupdateHomework(state.textValue));
                  },
                ),
              ],

            )),



          ],
        ),
      ),
      context: viewService.context);
}
